from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver=webdriver.Edge()
driver.get('http://10.59.9.12:7001/')
# ①　登录成功
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
driver.find_element(By.NAME,'username').send_keys('13012558376')
driver.find_element(By.NAME,'password').send_keys('123456Aa')
time.sleep(10)
driver.find_element(By.CLASS_NAME,'finish-btn').click()
time.sleep(3)
# ②　首页商品列表
driver.find_element(By.LINK_TEXT,'首页').click()
# ③　商品搜索
driver.find_element(By.CSS_SELECTOR,'.search-input').send_keys('宋牌')
driver.find_element(By.CLASS_NAME,'search-input-btn').click()
time.sleep(3)
# ④　商品详情
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img').click()
# ⑤　加入购物车
driver.find_element(By.ID,'add-cart').click()
driver.find_element(By.XPATH,'//a[@class="nav-settcart"]').click()
driver.find_element(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[2]/td[1]/input').click()

# ⑥　确认订单
driver.find_element(By.CLASS_NAME,'ask-btn').click()
# ⑦　创建订单并支付
driver.find_element(By.ID,'order-button').click()
time.sleep(5)
# ⑧　获取所有窗口句柄
all_window=driver.window_handles
# ⑨　打印获取所有窗口句柄
print(all_window)
# ⑩　切换窗口
driver.switch_to.window(driver.window_handles[-1])
# ⑪　退出浏览器技术
driver.close()